package com.dsh.userLogin.controller;
import com.dsh.model.Result;
import com.dsh.userLogin.entity.BackstageUser;
import com.dsh.userLogin.entity.vo.LoginParams;
import com.dsh.userLogin.service.AdminLoginService;
import com.dsh.userLogin.util.MessageTypeUtil;
import com.dsh.util.MD5AndKL;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "管理员登录")
@RestController
@RequestMapping("/adminLogin")
public class AdminLoginController {
    @Resource
    AdminLoginService adminLoginService;

    @RequestMapping(value = "/login",method= RequestMethod.POST)
    public Result<BackstageUser> adminLogin(@RequestBody LoginParams loginParams){
        LoginParams loginParams1 = new LoginParams();
        loginParams1.setPassword(MD5AndKL.MD5(loginParams.getPassword()));
        loginParams1.setUsername(loginParams.getUsername());
        BackstageUser backstageUser = adminLoginService.selectForAdminUsernameAndPassword(loginParams1);
        System.out.println(loginParams1);
        if (null != backstageUser){
            return Result.success(backstageUser, MessageTypeUtil.USERNAME_OR_PASSWORD_EMPTY);
        }
        else {
            return Result.failed(MessageTypeUtil.USERNAME_OR_PASSWORD_NOT_EMPTY);
        }
    }
}
